﻿using MaterialManagement.API.Application.Command.MesWorkOrder;
using MaterialManagement.API.Dtos;
using MaterialManagement.Domain.MesWorkOrder;
using MaterialManagement.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace MaterialManagement.API.Controllers
{
    /// <summary>
    /// BOM控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BOMController : ControllerBase
    {
        private readonly IMediator mediator;

        public BOMController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 新增BOM接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> CreateBOM(CreateBOMCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询BOM接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIPaging<BOMInformationModel>> GetBOM([FromQuery]GetBOMCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除BOM接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<int>> DeleteBOM([FromQuery]DeleteBOMCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 根据编号查询BOM信息接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<BOMInformationModel>> GetCodeBOM([FromQuery]GetCodeBOMCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 根据编号查询BOM物料接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<BOMMaterialDto>>> GetCodeMaterial([FromQuery]GetCodeMaterialCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request);
        }
    }
}
